package com.naire.modul.dictionary.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.common.action.GeneralAction;
import net.common.manager.DictManager;
import net.common.util.GsonUtils;

import com.naire.modul.dictionary.service.DictionaryDeleteService;
import com.naire.modul.dictionary.service.DictionaryEditorService;
import com.naire.modul.dictionary.service.DictionaryFindService;
import com.naire.modul.dictionary.vo.DictionaryVo;

public class DictionaryAction extends GeneralAction {

	private static final long serialVersionUID = 7127573666355745443L;

	private DictionaryVo bean = new DictionaryVo();
	private List<DictionaryVo> list = new ArrayList<DictionaryVo>();
	private String data;

	public String search() throws Exception {
		Collection<DictionaryVo> c = DictManager.get(bean.getSort_num());
		if (c != null) {
			list.addAll(c);
		}
		return SUCCESS;
	}

	public String treePage() throws Exception {
		data = GsonUtils.getGson(DictManager.get("0001"));
		return SUCCESS;
	}

	public String editor() throws Exception {
		DictionaryEditorService service = new DictionaryEditorService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}

	public String find() throws Exception {
		String num = bean.getSort_num();
		if (bean.getDict_id() != null) {
			DictionaryFindService service = new DictionaryFindService();
			service.setId(bean.getDict_id());
			service.invoke();
			bean = service.getBean();
			bean.setSort_num(num);
		}
		return SUCCESS;
	}

	public String delete() throws Exception {
		DictionaryDeleteService service = new DictionaryDeleteService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}

	public DictionaryVo getBean() {
		return bean;
	}

	public void setBean(DictionaryVo bean) {
		this.bean = bean;
	}

	public List<DictionaryVo> getList() {
		return list;
	}

	public void setList(List<DictionaryVo> list) {
		this.list = list;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}
}
